package com.jiuzhe.commercial.ui.house;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.jiangyy.easydialog.SingleChoiceDialog;
import com.jiuzhe.commercial.R;
import com.jiuzhe.commercial.base.BaseActivity;
import com.jiuzhe.commercial.bean.HouseStayBean;
import com.jiuzhe.commercial.utils.UIUtils;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by huanghao on 2018/6/2.
 */

public class HomeStayTypeActivity extends BaseActivity {
    @BindView(R.id.et_city)
    TextView etCity;
    @BindView(R.id.tv_wifi)
    TextView tvWifi;
    @BindView(R.id.tv_room)
    TextView tvRoom;
    @BindView(R.id.tv_bed)
    TextView tvBed;
    @BindView(R.id.tv_bathroom)
    TextView tvBathroom;
    private int type;
    private HouseStayBean houseStayBean;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_homestay_type);
        setTitle("房源配套设施");
        setRringTitle("下一步");
        setOnClik();
    }

    private void setOnClik() {
        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addHomeStayType();

            }
        });
    }



    @Override
    protected void loadData() {
        houseStayBean = (HouseStayBean) getIntent().getSerializableExtra("room");
    }


    @OnClick({R.id.et_city,R.id.tv_wifi,R.id.tv_room,R.id.tv_bed,R.id.tv_bathroom})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.tv_wifi:
                new SingleChoiceDialog.Builder(this).setTitle("提示")
                        .addList(new String[]{"有", "无"})
                        .setOnItemClickListener(new SingleChoiceDialog.OnItemClickListener() {
                            @Override
                            public void OnItemClick(String title, int position) {
                                if ("有".equals(title)){
                                    houseStayBean.setWifi("1");
                                }else {
                                    houseStayBean.setWifi("0");
                                }
                                tvWifi.setText(title);
                                }
                        }).show();
                break;
            case R.id.tv_room:
                type = 1;
                getType(type);
                break;
            case R.id.tv_bed:
                type = 2;
                getType(type);
                break;
            case R.id.tv_bathroom:
                type = 3;
                getType(type);
                break;
            case R.id.et_city:
                new SingleChoiceDialog.Builder(this).setTitle("提示")
                        .addList(new String[]{"公寓型", "酒店型","住宅型"})
                        .setOnItemClickListener(new SingleChoiceDialog.OnItemClickListener() {
                            @Override
                            public void OnItemClick(String title, int position) {
                                etCity.setText(title);
                                if ("公寓型".equals(title)){
                                    houseStayBean.setRoomType("0");
                                }else if ("酒店型".equals(title)){
                                    houseStayBean.setRoomType("1");
                                }else if ("住宅型".equals(title)){
                                    houseStayBean.setRoomType("2");
                                }
                            }
                        }).show();
                break;
        }
    }

    private void getType(final int type) {
        new SingleChoiceDialog.Builder(this).setTitle("提示")
                .addList(new String[]{"1", "2","3","4"})
                .setOnItemClickListener(new SingleChoiceDialog.OnItemClickListener() {
                    @Override
                    public void OnItemClick(String title, int position) {
                        if (type == 1){
                            tvRoom.setText(title + "间");
                            houseStayBean.setBedroomNum(Integer.parseInt(title));
                        }else if (type == 2){
                            tvBed.setText(title + "张");
                            houseStayBean.setBedNum(Integer.parseInt(title));
                        }else if (type == 3){
                            tvBathroom.setText(title + "个");}
                            houseStayBean.setToiletNum(Integer.parseInt(title));
                    }
                }).show();
    }

    private void addHomeStayType() {

        String tType = etCity.getText().toString().trim();
        String tWift = tvWifi.getText().toString().trim();
        String tRoom = tvRoom.getText().toString().trim();
        String tBed = tvBed.getText().toString().trim();
        String tBathroom = tvBathroom.getText().toString().trim();
        if (TextUtils.isEmpty(tType)) {
            UIUtils.showToastSafe("请填写房源类型信息！");
            return;
        }
        if (TextUtils.isEmpty(tWift)) {
            UIUtils.showToastSafe("请选择WiFi网格信息！");
            return;
        }
        if (TextUtils.isEmpty(tRoom)) {
            UIUtils.showToastSafe("请选择卧室间数！");
            return;
        }
        if (TextUtils.isEmpty(tBed)) {
            UIUtils.showToastSafe("请选择床位数！");
            return;
        }
        if (TextUtils.isEmpty(tBathroom)) {
            UIUtils.showToastSafe("请选择卫生间数！");
            return;
        }

        Intent intent = new Intent(HomeStayTypeActivity.this,HomeStayPrices.class);
        intent.putExtra("room",(Serializable)houseStayBean);
        startActivity(intent);

    }

}
